package com.qf.xiangqin.servlet;

import com.qf.xiangqin.dao.UserDao;
import com.qf.xiangqin.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/api/user/login")
public class UserLoginServlet extends HttpServlet {
   private UserDao dao = new UserDao();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("name");
        String password = req.getParameter("password");
        User user = dao.selectUser(username, password);
        if (user == null){
            resp.getWriter().println(400);
        }else{

            //            登录成功
            req.getSession().setAttribute("user",user);
//            返回结果
            resp.getWriter().println(200);
        }
    }
}
